package cn.iocoder.yudao.module.eval.dal.mysql.announcement;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.eval.controller.admin.announcement.vo.EvalAnnouncementPageReqVO;
import cn.iocoder.yudao.module.eval.dal.dataobject.announcement.EvalAnnouncementDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 公告发布 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface EvalAnnouncementMapper extends BaseMapperX<EvalAnnouncementDO> {

    default PageResult<EvalAnnouncementDO> selectPage(EvalAnnouncementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EvalAnnouncementDO>()
                .eqIfPresent(EvalAnnouncementDO::getPlanId, reqVO.getPlanId())
                .likeIfPresent(EvalAnnouncementDO::getTitle, reqVO.getTitle())
                .eqIfPresent(EvalAnnouncementDO::getAnnouncementType, reqVO.getAnnouncementType())
                .eqIfPresent(EvalAnnouncementDO::getPublishStatus, reqVO.getPublishStatus())
                .betweenIfPresent(EvalAnnouncementDO::getPublishTime, reqVO.getPublishTime())
                .betweenIfPresent(EvalAnnouncementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalAnnouncementDO::getId));
    }

    default List<EvalAnnouncementDO> selectList(EvalAnnouncementPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<EvalAnnouncementDO>()
                .eqIfPresent(EvalAnnouncementDO::getPlanId, reqVO.getPlanId())
                .likeIfPresent(EvalAnnouncementDO::getTitle, reqVO.getTitle())
                .eqIfPresent(EvalAnnouncementDO::getAnnouncementType, reqVO.getAnnouncementType())
                .eqIfPresent(EvalAnnouncementDO::getPublishStatus, reqVO.getPublishStatus())
                .betweenIfPresent(EvalAnnouncementDO::getPublishTime, reqVO.getPublishTime())
                .betweenIfPresent(EvalAnnouncementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalAnnouncementDO::getId));
    }

    default List<EvalAnnouncementDO> selectListByPlanId(Long planId) {
        return selectList(new LambdaQueryWrapperX<EvalAnnouncementDO>()
                .eq(EvalAnnouncementDO::getPlanId, planId)
                .orderByDesc(EvalAnnouncementDO::getId));
    }

    default List<EvalAnnouncementDO> selectListByPublishStatus(Integer publishStatus) {
        return selectList(new LambdaQueryWrapperX<EvalAnnouncementDO>()
                .eq(EvalAnnouncementDO::getPublishStatus, publishStatus)
                .orderByDesc(EvalAnnouncementDO::getId));
    }

}
